package com.kang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.bean.Process;
import com.kang.bean.Stage;
import com.kang.commons.Result;
import com.kang.mapper.ProcessMapper;
import com.kang.mapper.StageMapper;
import com.kang.service.ProcessService;
import com.kang.service.SseEmitterServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: service
 * @description: 流程服务类
 * @author: K.faWu
 * @create: 2022-04-11 15:09
 **/
@Service
public class ProcessServiceImpl extends ServiceImpl<ProcessMapper, Process> implements ProcessService {
    @Autowired
    private StageMapper stageMapper;

    @Override
    public void launch(Process process) {
        /*
         * 根据流程类型去找对应的处理人
         * 给处理人发送代办提醒，一小时内未处理短信提醒
         *
         */
        String processTypeCode = process.getProcessTypeCode();
        List<Stage> stageList= stageMapper.getByProcessTypeCode(processTypeCode);
        if (stageList!= null && stageList.size()!= 0){
            process.setRecipientId(stageList.get(0).getHandlerId());

        }else {
            Result.error("流程类型不存在！");
        }
        //通知处理人
        SseEmitterServer.sendMessage(stageList.get(0).getHandlerId().toString(), "");

    }
}
